<template>
  <div>
    <div class="his-hot" v-show="isShow">
      <div class="hd"><span>历史记录</span>
        <van-icon name="delete-o" @click="deleteHistory"/>
      </div>
      <van-tag plain size="large" type="default" v-for="(item, index) in historyKeywordList" :key="index"
               @click="handleClick(item)">{{ item }}
      </van-tag>
    </div>
    <div class="his-hot">
      <div class="hd"><span>热门搜索</span></div>
      <van-tag plain size="large" v-for="(val, index) in hotKeywordList" @click="handleClick(val.keyword)" :key="index"
               :type="val.is_hot === 1 ? 'danger' : 'default'">{{ val.keyword }}
      </van-tag>
    </div>
  </div>
</template>

<script>
import {ClearHistory} from "@/api/home";
import {Toast} from "vant";

export default {
  name: "HistoryHot",
  props: ["hotKeywordList", "historyKeywordList"],
  data() {
    return {
      isShow: true,
    }
  },
  methods: {
    handleClick(val) {
      this.$emit("tagClick", val);
    },
    async deleteHistory() {
      let code = await ClearHistory();
      this.isShow = false;
      Toast(`${code.errno === 0 ? "删除成功" : "删除失败"}`);
    }
  }
};
</script>

<style scoped lang="less">
.his-hot {
  z-index: 10000;
  background-color: #fff;
  padding: 0.09rem;

  .hd {
    display: flex;
    justify-content: space-between;
    font-size: 0.23rem;
    line-height: 23px;
    margin-bottom: 3px;
  }
}

.van-tag {
  margin: 3px;
}
</style>
